/*
 * @Author: 缄默
 * @Date: 2021-09-23 19:11:35
 * @LastEditors: 缄默
 * @LastEditTime: 2021-12-14 10:45:24
 */

#include <iostream>
using namespace std;

//实现化角色
class Implementor{
public:
    virtual void Operation() = 0;
    virtual ~Implementor() { }
protected:
    Implementor() { }
};

//具体实现化角色
class ConcreteImplementor1 :public Implementor {
public:
    void Operation() {
        cout << "ConcreteImplementor1 Operation..." << endl;
    }
};

class ConcreteImplementor2 :public Implementor {
public:
    void Operation() {
        cout << "ConcreteImplementor2 Operation..." << endl;
    }
};

//抽象化角色
class Abstraction {
public:
    virtual void Operation() = 0;
    virtual ~Abstraction() { }
protected:
    Implementor *_imp;
    Abstraction() { }
};
//扩展抽象化角色
class RefinedAbstraction :public Abstraction {
public:
    RefinedAbstraction(Implementor *imp) {
        _imp = imp;
    }
    void Operation() {
        _imp->Operation();
    }

};

int main() {
    Implementor *imp = new ConcreteImplementor1();
    Abstraction *abs = new RefinedAbstraction(imp);
    abs->Operation();

    delete imp;
    delete abs;

    Implementor *imp2 = new ConcreteImplementor2();
    Abstraction *abs2 = new RefinedAbstraction(imp);
    abs2->Operation();

    delete imp2;
    delete abs2;
    
    return 0;
}